package Week5.J0516;

import java.util.Scanner;

public class 体操队形_xv {
    static int N = 15, n = 0, ret = 0;
    static int[] arr = new int[N];
    static boolean[] isVis = new boolean[N];

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();


        for (int i = 1; i <= n; i++) {
            arr[i] = scanner.nextInt();
        }

        dfs(1);
        System.out.println(ret);

    }

    private static void dfs(int pos) {
        if (pos == n + 1) {
            ret++;
            return;
        }
        for (int i = 1; i <= n; i++) {
            if (isVis[i]) continue;
            if (isVis[arr[i]]) return;
            isVis[i] = true;
            dfs(pos + 1);
            isVis[i] = false;
        }
    }
}
